package com.adkfp.action;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.adkfp.utils.JsonUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.adkfp.bean.ADKControllerBean;
import com.adkfp.bean.ADKPowerGroupBean;
import com.adkfp.bean.ADKUserGroupBean;
import com.adkfp.bean.ADKUserInfoBean;
import com.adkfp.service.IADKUserGroupService;
import com.adkfp.service.IADKUserInfoService;

/**
 * class name:ADKUserGroupAction <BR>
 * class description: ADKUserGroup表的增删改查 <BR>
 * Remark: <BR>
 * @version 1.00 2019年01月03日
 * @author JACK)jackwei
 */
@Controller
@RequestMapping("aDKUserGroup")
public class ADKUserGroupAction {
	@Resource(name="aDKUserGroupService")
	private IADKUserGroupService aDKUserGroupService;
	
	@Resource(name="aDKUserInfoService")
	private IADKUserInfoService aDKUserInfoService;

  /**
 	* Method name: selectAll <BR>
 	* Description: 查询所有记录 <BR>
 	* Remark: <BR>
 	* @param bean
 	* @return  Object<BR>
 	*/
	@RequestMapping("selectAll")
	@ResponseBody
	public Object selectAll(ADKUserGroupBean bean) {
		List<ADKUserGroupBean> list = new ArrayList<>();
		list = aDKUserGroupService.findByCondition(bean);
		long count = aDKUserGroupService.findByConditionCount(bean);
		
		return list;
	}
	
	/**
	 * Method name: index <BR>
	 * Description: 转发到页面 <BR>
	 * Remark: <BR>
	 * @return  String<BR>
	 */
	@RequestMapping("index")
	public String index() {
		return "aDKUserGroup/UserGroup";
	}
	
	@RequestMapping("index1")
	public String index1() {
		return "aDKUserGroup/aDKUserGroup";
	}
	

	
	@RequestMapping("UserGroupTop")
	public Object UserGroupTop(HttpServletRequest request,String autoId,ADKUserGroupBean ugBean) {
		ugBean.setAutoID(Integer.parseInt(autoId));
		request.setAttribute("ugBean",ugBean);
		return "aDKUserGroup/UserGroupTop";
	}
	
	//用于跳转人员权限管理中的查看
	@RequestMapping("chaKanUserGroup")
	public String chaKanUserGroup(HttpServletRequest request,String userid,ADKUserInfoBean bean) {
		if(bean.getAutoid() != null && !bean.getAutoid().equals("")) {
			bean=aDKUserInfoService.finduseridById(userid);
		}
		request.setAttribute("userid",bean);
		return "aDKUserGroup/chaKanUserGroup";
	}
	
	
	
	
	//增加人员权限
	@RequestMapping("addUserPGroup")
	@ResponseBody
	public void addUserPGroup(ADKUserGroupBean usergroup,String groupID,String ckData1) {
		System.err.println("----增加人员权限   进入powergroup方法----");
		//JSONObject  json=JSONObject.fromObject(ckData1);
		JSONArray arrayList= JSONArray.parseArray(ckData1);
		System.out.println("groupID的值是------------"+groupID);
		System.out.println("JSONArray的值是------------"+arrayList);
        //转换为目标对象list
       // List<ADKUserGroupBean> groupList = JSONObject.parseArray(arrayList.toJSONString(), ADKUserGroupBean.class);
		//List<ADKUserGroupBean> bean = new ArrayList<>();
		for (Object object : arrayList) {
			usergroup.setGroupID(Integer.parseInt(groupID));
			usergroup.setUserID(object.toString());
			aDKUserGroupService.insert(usergroup);
			System.out.println("userid 的值是----"+object);
		}
		//aDKUserGroupService.update(powergroup);
	}
	
	
/*	//转发到aDKUserGroupRight页面
	@RequestMapping("UserPowerGroupRight")
	public String UserPowerGroupRight(HttpServletRequest request,Integer id,HttpServletResponse response) {
		ADKPowerGroupBean pgBean = new ADKPowerGroupBean();	
		if(id != null && !id.equals(" ")){
			pgBean=aDKPowerGroupService.findById(id);
		}
		request.setAttribute("pgUserBean",pgBean);
		return "aDKUserGroup/aDKUserGroupRight";
	}*/
	
	//删除人员权限
	
			@RequestMapping("deleteUserPG")
			@ResponseBody
			public void deleteUserPG(String groupid,String userid) {
				 System.out.println("删除功能中  groupID是------"+groupid);
				 System.out.println("删除功能中  userID是------"+userid);
				aDKUserGroupService.delete(Integer.parseInt(groupid),userid);
			}
}